<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>分享云管理系统</title>
<link href="/Resource/css/layout.css" rel="stylesheet" type="text/css" />
<link href="/Resource/css/wysiwyg.css" rel="stylesheet" type="text/css" />

    <link href="/Resource/pages/css/layui.css" rel="stylesheet" type="text/css" />
<!-- Theme Start -->
<link href="/Resource/css/blue/styles.css" rel="stylesheet" type="text/css" />
<!-- Theme End -->
    <script type="text/javascript" src="//libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/Resource/js/common.js"></script>
    <script language='javascript' src='/Resource/js/jquery.cookie.js'></script>

    <!--pages-->
    <script language='javascript' src='/Resource/pages/layui.js'></script>
</head>
<body id="homepage">
<!-- Right Side/Main Content Start -->
<div id="rightside">
    <div class="databox">
        <div class="mb10 clearfix">
            <div  >
                <span >支付状态:</span>
                <select id="paystatus_select" >
                    <option value ="" >全部</option>
                    <option value ="0"  >未支付</option>
                    <option value="1" >已支付</option>
                </select>
            </div>

            <div class="left mt5">

                <div class="layui-form-pane" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">时间选择</label>
                        <div class="layui-input-inline">
                            <input class="layui-input" placeholder="开始日" id="LAY_demorange_s">
                        </div>
                        <div class="layui-input-inline">
                            <input class="layui-input" placeholder="截止日" id="LAY_demorange_e">
                        </div>
                        <input class="mt20"  onclick="orderexport()" type="button" style="width:80px" value="导出订单" />
                    </div>

                </div>


            </div>

            <div class="right">
                <form  style="margin-bottom:0;">
                    <div>
                        <input id="phone"  type="text" name="phone" value="<?php echo ($phone); ?>" style="width:250px;" class="inputbox" placeholder="输手机号查找"/>
                        <!--<input id="paystatus_input"  type="text" name="paystatus" value="" style="display: none"/>-->
                        <!--<input id="startdate"  type="text" name="startdate" value="" style="display: none"/>-->
                        <!--<input id="enddate"  type="text" name="enddate" value="" style="display: none"/>-->
                        <input type="button" class="btn" style="width:80px" value="查  找" onclick="search()" />
                    </div>
                </form>
            </div>
        </div>
        <table id="ordertable"  width="100%" border="1" cellspacing="0" cellpadding="0" class="tablestyle mb20" style="text-align:left;">
            <thead>
            <th width="80">订单ID</th>
            <th width="100">支付信息</th>
            <th>订单详情</th>
            <th width="100">客户信息</th>
            <th width="100">地址</th>
            <th width="100">创建时间</th>
            <thead>

            <tbody id="orderlist">


            </tbody>
        </table>


        <div id="pages"></div>
    </div>

    <!--<nav aria-label="Page navigation">-->
        <!--<ul class="pagination" id="pagination"></ul>-->
    <!--</nav>-->
</div>
<div id="leftside">


    <div class="user">
        <p>欢迎您:</p>
        <p class="username"><?php echo ($adminname); ?></p>
        <p class="userbtn"><a href="#" onclick="logout()" title="">退出</a></p>
    </div>
    <div id="footer">
        &copy; 2016 分享云
    </div>
</div>

</body>


<script type="text/javascript">

    function search() {
        var url = "/Admin/index/order/adminname/<?php echo ($adminname); ?>";

        var startdate  = $("#LAY_demorange_s").val();
        var enddate  = document.getElementById('LAY_demorange_e').value;

        if(!isEmpty($("#phone").val())){
            url = url+"/phone/"+$("#phone").val();
        }
        if(!isEmpty($("#paystatus_select").val())){
            url = url+"/paystatus/"+$("#paystatus_select").val();
        }
        if(!isEmpty(startdate)){
            url = url+"/startdate/"+startdate;
        }
        if(!isEmpty(enddate)){
            url = url+"/enddate/"+enddate;
        }
        window.location = url;

    }

    $.cookie("canload", "0", {expires: 7, path: '/'});
    layui.use(['laypage', 'layer'], function() {
        var laypage = layui.laypage;

        laypage({
            cont: 'pages'
            ,pages: "<?php echo ($totalpage); ?>"
            ,curr:"<?php echo ($currentpage); ?>"
            ,skin: '#1E9FFF'
            ,jump: function(obj){
//               console.info(obj.curr);
                var url = "/Admin/index/order/adminname/<?php echo ($adminname); ?>";
            if(!isEmpty("<?php echo ($phone); ?>")){
                url = url+"/phone/<?php echo ($phone); ?>";
            }
            if(!isEmpty("<?php echo ($paystatus); ?>")){
                url = url+"/paystatus/<?php echo ($paystatus); ?>";
            }
            if(!isEmpty("<?php echo ($startdate); ?>")){
                url = url+"/startdate/<?php echo ($startdate); ?>";
            }
            if(!isEmpty("<?php echo ($enddate); ?>")){
                url = url+"/enddate/<?php echo ($enddate); ?>";
            }
            if($.cookie("canload") == 1){
                window.location = url+"/currentpage/"+obj.curr;
            }

            }
        });
        $.cookie("canload", "1", {expires: 7, path: '/'});
    });


    layui.use('laydate', function(){
        var laydate = layui.laydate;

        var start = {
             min: '2016-10-28 00:00:00'
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
//                 alert(datas);
//                document.getElementById('startdate').value = datas;
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }

        };

        var end = {
             max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
//                document.getElementById('enddate').value = datas;
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        };
        document.getElementById('LAY_demorange_e').onclick = function(){
            end.elem = this
            laydate(end);
        }

    });

//    document.getElementById('enddate').value = "<?php echo ($enddate); ?>";
//    document.getElementById('startdate').value = "<?php echo ($startdate); ?>";
    document.getElementById('LAY_demorange_e').value = "<?php echo ($enddate); ?>";
    document.getElementById('LAY_demorange_s').value = "<?php echo ($startdate); ?>";


    if (!isEmpty("<?php echo ($adminname); ?>")) {
        $.cookie("adminname", "<?php echo ($adminname); ?>", {expires: 7, path: '/'});
    } else {
        logout();
    }

    function logout() {
         $.removeCookie('adminname',{ expires: 7, path: '/' });
         window.location = "/Admin/index/logout/adminname/<?php echo ($adminname); ?>";
         return;
    }



    inittable();

    function inittable() {
        var t=document.getElementById("orderlist");     //获取Table
        var length= t.rows.length;             //获得Table下的行数
        if(length!=0){                      //如果有行，则清空
            for(var i=length-1;i>=0;i--)
            {
                t.deleteRow(i);
            }
        }
        var temp = '<?php echo ($orders); ?>';
        var orders=JSON.parse(temp);
        if(!isEmpty(orders) &&orders.length>0){
            for(var i = 0; i < orders.length; i++){
                var tr=document.createElement("tr");
                tr.id=i;

                var remark ='<br>['+orders[i]["remark"]+']';
                if(isEmpty(orders[i]["remark"])){
                    remark = '';
                }


                var td='<td>'+orders[i]["id"]+'</td>' +

                        '<td>总金额:'+orders[i]["totalprice"]+'元'+
                        '<br>支付渠道:'+orders[i]["paytype"]+
                        '<br>支付状态:'+orders[i]["paystatus"]+
                        '</td>' +

                        '<td>'+orders[i]["orderdata"]+'</td>' +

                        '<td>'+orders[i]["username"]+
                        '<br>'+orders[i]["userphone"]+
                        remark+
                        '</td>' +

                        '<td>'+orders[i]["address"]+'</td>' +
                        '<td>'+orders[i]["createtime"]+'</td>';
                tr.innerHTML = td;
                document.getElementById('orderlist').appendChild(tr);
            }

        }else{
            var r = t.insertRow();
            var c = r.insertCell();
            c.innerHTML="暂无数据";
            document.getElementById('orderlist').appendChild(r);
        }


    }
    $("#paystatus_select").val("<?php echo ($paystatus); ?>");
    document.getElementById('paystatus_input').value ="<?php echo ($paystatus); ?>";
    $("#paystatus_select").change(function(){
//        console.info('paystatus_select = '+$("#paystatus_select").val());
        document.getElementById('paystatus_input').value = $("#paystatus_select").val();
     });

    function orderexport() {
        var startdate  = $("#LAY_demorange_s").val();
        var enddate  = document.getElementById('LAY_demorange_e').value;

        if(isEmpty(startdate)){
            alert('请选择起始时间');
            return;
        }
        if(isEmpty(enddate)){
            alert('请选择截止时间');
            return;
        }

        var url = "/Admin/index/orderexport/adminname/<?php echo ($adminname); ?>";


        if(!isEmpty($("#phone").val())){
            url = url+"/phone/"+$("#phone").val();
        }
        if(!isEmpty($("#paystatus_select").val())){
            url = url+"/paystatus/"+$("#paystatus_select").val();
        }
        if(!isEmpty(startdate)){
            url = url+"/startdate/"+startdate;
        }
        if(!isEmpty(enddate)){
            url = url+"/enddate/"+enddate;
        }
        window.location = url;
    }


</script>


</html>